package com.groupbuying.currency.producer.mq;

import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Properties;

@Component
public class CurrencyMQProducer {
    public static final Logger LOGGER = LoggerFactory.getLogger(CurrencyMQProducer.class);

    @Bean
    public Producer getCurrencyMQProducer() {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.AccessKey, CurrencyMQConfig.ACCESS_KEY);
        properties.put(PropertyKeyConst.SecretKey, CurrencyMQConfig.SECRET_KEY);
        properties.put(PropertyKeyConst.NAMESRV_ADDR, CurrencyMQConfig.NAMESRV_ADDR);
        Producer producer = ONSFactory.createProducer(properties);
        try {
            producer.start();
            LOGGER.info("producer is start !!!");
        } catch (Exception var4) {
            LOGGER.error(String.format("producer is error", var4.getMessage(), var4));
        }
        return producer;
    }
}
